\section{rank --- Rank of a Matrix}
\label{fn:rank}
\index{rank()}
\index{rank of a matrix}
\index{matrix!rank}
\begin{rail}
Rank : 'rank' '(' Matrix (',' Scalar ) ? ')' ;
\end{rail}

\verb+rank+ calculates the rank of the argument matrix.  The rank
of a matrix is the number of non-zero singular values of that matrix.
However since numeric computation introduces errors, the singular
values are actually tested against a set tolerance value.  The
optional scalar argument, if present, specifies the tolerance,
otherwise the default of the triple-product of the greater dimension of the
argument, the 2-norm of the matrix and machine epsilon is used.

$\Longrightarrow$ This is not an \RLaB\ built-in function.  This function
is normally loaded on start-up from the \verb+rank.r+ file in the
standard \verb+rlib+ directory. Use of the \verb+-r+ option, incorrectly 
setting the \verb+RLAB_LIB_DIR+ environmental variable, or modifying
\verb+rank.r+ may make this function unavailable.




\paragraph{Example}
\index{example of rank()}
\index{rank()!example}
\begin{verbatim}
> a = rand(5,5)
 a =
     0.44      0.741      0.842      0.599      0.239  
    0.685      0.313      0.652      0.455      0.465  
    0.129      0.759      0.386      0.658      0.546  
     0.79      0.151      0.583      0.232      0.801  
    0.868      0.325      0.205      0.797      0.247  
> svd(a).sigma
 sigma =
      2.6      0.835      0.624      0.442     0.0475  
> rank(a)
        5
> b = [a,a;a,a];
> svd(b).sigma
 sigma =
 matrix columns 1 thru 6
      5.2       1.67       1.25      0.884      0.095   1.63e-16  

 matrix columns 7 thru 10
 6.15e-17   2.93e-17   1.04e-17   1.45e-18  
> rank(b)
        5
\end{verbatim}

See also: Page~\pageref{fn:epsilon} \verb+epsilon()+,
Page~\pageref{fn:norm} \verb+norm()+,
Page~\pageref{fn:size} \verb+size()+.

\newpage



